package com.example.avmanagerweb.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.avmanagerweb.entity.SysDevic;
import com.example.avmanagerweb.entity.Videoserverqry;
import com.example.avmanagerweb.entity.vo.RtmpParameterVo;
import com.example.avmanagerweb.result.RLIST;
import com.example.avmanagerweb.service.SysDevicService;
import com.example.avmanagerweb.service.VideoserverqryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author xg
 * @since 2023-10-30
 */
@RestController
@RequestMapping("/videoserverqry")
public class VideoserverqryController {

    @Autowired
    private VideoserverqryService videoserverqryService;
    @Autowired
    private SysDevicService sysDevicService;
    @PostMapping("/getRtmpUrl")
    public RLIST getRtmpUrl(@RequestBody RtmpParameterVo rtmpParameterVo){
        SysDevic one = new SysDevic();
        System.out.println(rtmpParameterVo.toString());
        if(rtmpParameterVo.getDevNo() == null || rtmpParameterVo.getDevNo() == ""){
            return RLIST.error().message("设备不能为空");
        }
        if(rtmpParameterVo.getDvId() == null || rtmpParameterVo.getDvId() == 0){

            QueryWrapper wrapper = new QueryWrapper();
            wrapper.eq("dvNum",rtmpParameterVo.getDevNo());
            one = sysDevicService.getOne(wrapper);
            rtmpParameterVo.setDvId(one.getDvid());
        }
        Videoserverqry video = videoserverqryService.getById(34);
        long l = System.currentTimeMillis();
        String RtmpUrl = "rtmp://"+video.getServerip()+":"+video.getPort()+"/live/stream"+rtmpParameterVo.getDvId()+"?sign="+l;

        return RLIST.ok().data("RtmpUrl",RtmpUrl);
    }

}

